// 之前在react里面解构的，现在还是在react解构
import { useState, FC } from 'react';
import Child from './components/Child';

// FC表示函数组件
const Home: FC = () => {
  // <number>表示泛型, 表示我们这个count是数字类型
  const [count, set_count] = useState<number>(5);

  // 函数参数的类型必须要自己写
  const increment = (num: number): void => {
    set_count((v) => v + num);
  };

  const decrement = (num: number): void => {
    set_count((v) => v - num);
  };

  return (
    <>
      <h3>计数器</h3>
      <button onClick={() => decrement(3)}>-</button>
      <span>{count}</span>
      <button onClick={() => increment(2)}>+</button>

      <Child count={count} />
    </>
  );
};

export default Home;
